package com.easybbs.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.easybbs.controller.base.ABaseController;
import com.easybbs.entity.enums.UserRoleEnum;
import com.easybbs.entity.po.UserInfo;
import com.easybbs.entity.vo.ResponseVO;
import com.easybbs.service.UserInfoService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: yudaxian
 * @Description: 测试
 * @DateTime: 2024/10/18 9:08
 **/
@RestController
@SaCheckLogin
@Api(tags = "测试")
@RequestMapping("/test")
public class TestController extends ABaseController {

    @Resource
    private UserInfoService userInfoService;

    @SaCheckRole("admin")
    @GetMapping("/admin")
    public ResponseVO testAdmin() {
        return getSuccessResponseVO("web test admin");
    }

    @SaCheckRole("user")
    @GetMapping("/user")
    public ResponseVO testUser() {
        return getSuccessResponseVO("web test user");
    }

    @GetMapping("/userInfo")
    public ResponseVO testUserInfo() {
        String loginId = (String) StpUtil.getLoginId();
        UserInfo userInfoByUserId = userInfoService.getUserInfoByUserId(loginId);
        return getSuccessResponseVO(userInfoByUserId);
    }
}
